package com.wwj.airline.Controller;

import com.wwj.airline.pojo.City;
import com.wwj.airline.Dao.CityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/city")
public class CityHandler {
    @Autowired(required = false)
    private CityRepository cityRepository;

    @GetMapping("/findAll")
    public List<City> findAll(){
        return cityRepository.findAll();
    }

    @GetMapping("/findById/{id}")
    public City findById(@PathVariable("id") Long id){
        return cityRepository.findById(id);
    }

    @PostMapping("/save")
    public void save(@RequestBody City city){
        cityRepository.save(city);
    }

    @PutMapping("/update")
    public void update(@RequestBody City city){
        cityRepository.update(city);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id){
        cityRepository.deleteById(id);
    }
}
